/*
 * @lc app=leetcode.cn id=654 lang=cpp
 *
 * [654] 最大二叉树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* constructMaximumBinaryTree(vector<int>& nums) {
        //find_max_of_nums
        return build(nums,0,nums.size()-1);
        //left right

        //make node 

        //
    }

    TreeNode * build(vector<int>nums,int lo,int hi){

        if(lo > hi) return nullptr;

        int index = -1; 
        int max_value =-9999;
        for(int i=0;i<hi;i++){
            if(max_value< nums[i]){
                index++;
                max_value = nums[i];
            }
        }

        TreeNode * root ;
        root->val = max_value;

        build(nums,lo,index-1);
        build(nums,index+1,hi);

        return root;

    }


};
// @lc code=end

